package xu.zhi.qing.user.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xu.zhi.qing.common.service.BaseService;
import xu.zhi.qing.exception.LoginErrorException;
import xu.zhi.qing.user.entity.Admin;
import xu.zhi.qing.user.entity.User;

@Transactional
@Service
public class AdminService extends BaseService<Admin> {

	public void hideUser(int id) {
		User user = userDao.findById(id);
		user.setStatus(User.STATUS_PRIVATE);
		userDao.updateById(user);

	}

	public void enableUser(int id) {
		User user = userDao.findById(id);
		user.setStatus(User.STATUS_PUBLIC);
		userDao.updateById(user);

	}

	public Admin login(Admin admin) throws LoginErrorException{
		Admin adminReturn = adminDao.findByUsername(admin.getUsername());
		if (adminReturn==null) {
			throw new LoginErrorException("用户不存在！");
		}

		if (!adminReturn.getPassword().equals(admin.getPassword())) {
			throw new LoginErrorException("密码不正确！");
		}

		return adminReturn;
	}

}
